
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>页面1</title>
</head>
<body>
    <?php 
            if($_POST["submit"] == "submit"){
                # $data = [ "apple" => 4, "banana" => 2, "orange" => 3, "pear" => 1];
                # echo json_encode($data);
                 $userName=$_GET["userName"];
                 $password=$_GET["password"];
                $userId=$_GET["userId"];
                 $ip = "localhost"; // 数据库服务器地址
                 $user = "root";     // 数据库用户名
                 $pwd = "root";     // 数据库密码
                 $db = "test";     // 数据库名称
                 // 创建连接
                 $conn = mysqli_connect($ip, $user, $pwd, $db);
                 // 检查连接
                 if (!$conn) {
                     die("连接失败: " .mysqli_connect_error());
                 }
                 echo "连接成功";
                 
                 # 预处理语句
                 $stmt = $conn -> prepare(" INSERT INTO test (name, password) VALUES (?, ?) ");
                 if ($stmt === false) {
                      die("预处理语句失败: " . $conn->error);
                  }
              
                  # 绑定参数
                 $stmt->bind_param("ss", $name, $password); // "ss" 表示两个字符串参数
              
                 // 执行语句
                  if ($stmt -> execute()) {
                      echo "新记录插入成功";
                  } else {
                      echo "错误:" . $stmt->error;
                  }
              
                  // 关闭预处理语句
                  $stmt->close();
                  // 关闭连接
                  $conn->close();
             }
             else{
                 echo "abc";
             }
    ?>
    
    <form metho="get" action="insert.php">

        用户名:<input name="userName" type="text">
        <br>
        密 码:<input name="password" type="password">
        <br>
        <input type="submit" name="submit" value="submit">
    </form>
</body>
</html>